<?php

namespace App\Controller;

use App\Grpc\CalculateClient;
use App\Grpc\LogClient;
use Grpc\CalculateRequest;
use Grpc\LoggerRequest;
use Hyperf\HttpServer\Contract\RequestInterface;

class LogController extends AbstractController
{
    /**
     * @var LogClient
     */
    public $client;

    public function __construct(LogClient $client)
    {
        $this->client = $client;
    }

    public function debug(RequestInterface $request)
    {
        $log = new LoggerRequest();
        $log->setFrom("api");
        $log->setMsg($request->query("msg","吃葡萄不吐葡萄皮"));
        $log->setTime(time());
        $log->setVersion("1.0");
        $response = $this->client->debug($log);
        return [
            "code" => 0 , "msg"=>"ok" ,"data"=>["result"=>$response->getSuccess() ? "1" : "0"]
        ];
    }
}